Help with "Set-Contact" during Import
I have a couple of hundred contacts I am trying to import into Exchange 2007 SP3.
I can import the contacts using shell command: "import-csv c:\import.csv | forEach { New-MailContact -Name $._displayname ....}"
however, I am also trying to find a way to set the "Company" attribute with the same command, but so far I can't get it to work.
I have tried this "import-csv c:\import.csv | forEach { New-MailContact -Name $._displayname ....} |
set-contact -Company $_.Company
however, I receive a warning for each contact during import stating "THe command completed successfully but no settings of "domain/OU/Contacts/users name" have been modified."
The contacts are created but the Company attribute is not set. I have tried other combinations but cant seem to find something that works.
How can I create new contacts and set attributes such as company with 1 command?
May 4th, 2012 5:43pm
Hi Mac1234,
Any updates?
Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
tnmff@microsoft.com.Frank Wang
TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
May 7th, 2012 3:20am
No dice with this command. I receive the following error for each user:
New-MailContact : A positional parameter cannot be found that accepts argument 'Set-Contact'
+CategoryInfo : InvalidArgument : (:) [New-MailContact], ParameterBindingException
+FullyQualifiedErrorid: PositionalParameterNotFound
May 7th, 2012 2:14pm
Hi Mac1234,
I tested it in my lab and both MVP's cmdlets work.
Did you also try to run the cmdlet in EMS directly?
C:\>import-csv c:\import.csv
| forEach {
>>contact = New-MailContact
-Name $._displayname
-ExternalEmailAddress $_.ExternalEmailAddress
#It works with/without the semicolon in the above cmdlet
>>Set-contact -identity $contact.name
-Company $_.Company
>>}
>>
----------
Csv file format:
displayname,ExternalEmailAddress,company
s1,s1@ss.com,abc
s2,s2@ss.com,cdeFrank Wang
TechNet Community Support
Free Windows Admin Tool Kit Click here and download it now
May 7th, 2012 11:26pm
This might work better, but the use of "$_" may be the real problem
(or at least a confusing factor):
"import-csv c:\import.csv | forEach { New-MailContact -Name
$._displayname .... | set-contact -Company $_.Company }"
Just tested and this code appears to work for me. Much thanks.
When you say $_ may be the problem - how so?
May 8th, 2012 2:30pm
On Tue, 8 May 2012 18:30:02 +0000, mac1234 wrote:
>This might work better, but the use of "$_" may be the real problem (or at least a confusing factor): "import-csv c:\import.csv | forEach { New-MailContact -Name
>
>$._displayname .... | set-contact -Company $_.Company }"
>
>Just tested and this code appears to work for me. Much thanks.
>
>When you say $_ may be the problem - how so?
As I said, "or a confusing factor".
You have two pipelines. The "$_" is taken to mean "self". From which
pipeline is the "$_" in the "set-contact" taken? :-)
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
May 8th, 2012 6:01pm